﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using White.WebBrowser;
using White.WebBrowser.Silverlight;
using White.Core.UIItems;
using System.Windows.Automation;
using White.Core.UIItems.WindowStripControls;
using White.Core.InputDevices;

namespace SilverlightLesson1
{
    class Program
    {
        static void Main(string[] args)
        {
            InternetExplorerWindow browserWindow = InternetExplorer.Launch("http://localhost:1903/GyroUITestPage.aspx", "Home - Windows Internet Explorer");
            //FirefoxWindow browserWindow = Firefox.Launch("http://csrv-sps2010:8888/GyroUITestPage.aspx");            
            SilverlightDocument document = browserWindow.SilverlightDocument;
            Button button = document.Get(White.Core.UIItems.Finders.SearchCriteria.ByText("login")) as Button;
            button.Click();
            button.Click();
            System.Threading.Thread.Sleep(2500);
            TextBox t = document.Get(White.Core.UIItems.Finders.SearchCriteria.ByNativeProperty(AutomationElement.AutomationIdProperty, "UserName")) as TextBox;            
            t.Text = "venkatesh.chandrasekharan@asia.xchanging.com";
            t = document.Get(White.Core.UIItems.Finders.SearchCriteria.ByNativeProperty(AutomationElement.AutomationIdProperty, "Password")) as TextBox;
            t.Text = "Welcome123";
            button = document.Get(White.Core.UIItems.Finders.SearchCriteria.ByAutomationId("loginButton")) as Button;
            button.Focus();            
            button.Click();
            //Console.ReadLine();
            System.Threading.Thread.Sleep(1500);
            MenuBar mb = document.Get(White.Core.UIItems.Finders.SearchCriteria.ByAutomationId("rdRootMenu")) as MenuBar;                                
            White.Core.UIItems.MenuItems.Menu mi = mb.MenuItemBy(White.Core.UIItems.Finders.SearchCriteria.ByText("Automation"));
            Mouse.Instance.Location = mi.Location;
            mb = document.Get(White.Core.UIItems.Finders.SearchCriteria.ByAutomationId("rdRootMenu")) as MenuBar;
            mi = mb.MenuItemBy(White.Core.UIItems.Finders.SearchCriteria.ByText("Automation"));
            var result = mi.ChildMenus.Where(x => x.Name.Equals("Projects", StringComparison.InvariantCultureIgnoreCase)).ToList();
            White.Core.UIItems.MenuItems.Menu mimi = result[0] as White.Core.UIItems.MenuItems.Menu;
            mimi.Click();
            //Label label = document.Get<Label>("status");
        }
    }
}
